from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-16 14:08:45.046174
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 16, Feb, 2021
Time: 14:08:48
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.1950
Nobs: 204.000 HQIC: -47.0667
Log likelihood: 2346.04 FPE: 2.00594e-21
AIC: -47.6589 Det(Omega_mle): 1.30396e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.468198 0.139163 3.364 0.001
L1.Burgenland 0.081138 0.071549 1.134 0.257
L1.Kärnten -0.215508 0.060342 -3.571 0.000
L1.Niederösterreich 0.131459 0.165899 0.792 0.428
L1.Oberösterreich 0.237434 0.145884 1.628 0.104
L1.Salzburg 0.208201 0.076836 2.710 0.007
L1.Steiermark 0.105497 0.103814 1.016 0.310
L1.Tirol 0.141835 0.069278 2.047 0.041
L1.Vorarlberg -0.002362 0.063808 -0.037 0.970
L1.Wien -0.141968 0.137006 -1.036 0.300
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.480342 0.168715 2.847 0.004
L1.Burgenland 0.015162 0.086743 0.175 0.861
L1.Kärnten 0.356743 0.073156 4.876 0.000
L1.Niederösterreich 0.123037 0.201129 0.612 0.541
L1.Oberösterreich -0.137594 0.176864 -0.778 0.437
L1.Salzburg 0.193780 0.093153 2.080 0.038
L1.Steiermark 0.208424 0.125860 1.656 0.098
L1.Tirol 0.142967 0.083990 1.702 0.089
L1.Vorarlberg 0.165614 0.077358 2.141 0.032
L1.Wien -0.535878 0.166101 -3.226 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.312820 0.062103 5.037 0.000
L1.Burgenland 0.104803 0.031930 3.282 0.001
L1.Kärnten -0.017185 0.026929 -0.638 0.523
L1.Niederösterreich 0.085351 0.074035 1.153 0.249
L1.Oberösterreich 0.284485 0.065103 4.370 0.000
L1.Salzburg 0.001156 0.034289 0.034 0.973
L1.Steiermark -0.016904 0.046328 -0.365 0.715
L1.Tirol 0.083587 0.030916 2.704 0.007
L1.Vorarlberg 0.109715 0.028475 3.853 0.000
L1.Wien 0.057833 0.061141 0.946 0.344
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.225084 0.069908 3.220 0.001
L1.Burgenland -0.008121 0.035942 -0.226 0.821
L1.Kärnten 0.023193 0.030313 0.765 0.444
L1.Niederösterreich 0.044473 0.083338 0.534 0.594
L1.Oberösterreich 0.379106 0.073284 5.173 0.000
L1.Salzburg 0.090198 0.038598 2.337 0.019
L1.Steiermark 0.183300 0.052150 3.515 0.000
L1.Tirol 0.039569 0.034802 1.137 0.256
L1.Vorarlberg 0.089715 0.032053 2.799 0.005
L1.Wien -0.068215 0.068824 -0.991 0.322
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.518573 0.140001 3.704 0.000
L1.Burgenland 0.060520 0.071980 0.841 0.400
L1.Kärnten 0.015995 0.060706 0.263 0.792
L1.Niederösterreich -0.030013 0.166898 -0.180 0.857
L1.Oberösterreich 0.141271 0.146764 0.963 0.336
L1.Salzburg 0.056288 0.077299 0.728 0.467
L1.Steiermark 0.127827 0.104440 1.224 0.221
L1.Tirol 0.213426 0.069696 3.062 0.002
L1.Vorarlberg 0.025061 0.064192 0.390 0.696
L1.Wien -0.119284 0.137832 -0.865 0.387
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163391 0.098763 1.654 0.098
L1.Burgenland -0.020184 0.050778 -0.397 0.691
L1.Kärnten -0.007836 0.042825 -0.183 0.855
L1.Niederösterreich 0.118603 0.117737 1.007 0.314
L1.Oberösterreich 0.380533 0.103533 3.675 0.000
L1.Salzburg -0.015080 0.054530 -0.277 0.782
L1.Steiermark -0.019694 0.073676 -0.267 0.789
L1.Tirol 0.182889 0.049166 3.720 0.000
L1.Vorarlberg 0.038236 0.045284 0.844 0.398
L1.Wien 0.186358 0.097233 1.917 0.055
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.233996 0.127196 1.840 0.066
L1.Burgenland 0.058236 0.065396 0.891 0.373
L1.Kärnten -0.036037 0.055153 -0.653 0.514
L1.Niederösterreich -0.021326 0.151632 -0.141 0.888
L1.Oberösterreich -0.092194 0.133339 -0.691 0.489
L1.Salzburg 0.046286 0.070229 0.659 0.510
L1.Steiermark 0.394381 0.094887 4.156 0.000
L1.Tirol 0.480633 0.063321 7.590 0.000
L1.Vorarlberg 0.168947 0.058321 2.897 0.004
L1.Wien -0.231666 0.125225 -1.850 0.064
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.079871 0.153625 0.520 0.603
L1.Burgenland 0.028759 0.078984 0.364 0.716
L1.Kärnten -0.077378 0.066613 -1.162 0.245
L1.Niederösterreich 0.260717 0.183140 1.424 0.155
L1.Oberösterreich -0.023778 0.161046 -0.148 0.883
L1.Salzburg 0.244151 0.084822 2.878 0.004
L1.Steiermark 0.144711 0.114603 1.263 0.207
L1.Tirol 0.058581 0.076478 0.766 0.444
L1.Vorarlberg 0.052706 0.070439 0.748 0.454
L1.Wien 0.236164 0.151245 1.561 0.118
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.587913 0.082474 7.129 0.000
L1.Burgenland -0.033080 0.042403 -0.780 0.435
L1.Kärnten -0.012378 0.035761 -0.346 0.729
L1.Niederösterreich -0.028435 0.098318 -0.289 0.772
L1.Oberösterreich 0.298876 0.086457 3.457 0.001
L1.Salzburg 0.016526 0.045536 0.363 0.717
L1.Steiermark 0.004036 0.061524 0.066 0.948
L1.Tirol 0.079521 0.041057 1.937 0.053
L1.Vorarlberg 0.128643 0.037815 3.402 0.001
L1.Wien -0.035463 0.081196 -0.437 0.662
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.133258 0.038103 0.195952 0.250008 0.069348 0.103257 -0.049378 0.164681
Kärnten 0.133258 1.000000 0.008517 0.191394 0.167119 -0.117903 0.147188 0.005515 0.320500
Niederösterreich 0.038103 0.008517 1.000000 0.303652 0.082585 0.223043 0.135035 0.060463 0.355938
Oberösterreich 0.195952 0.191394 0.303652 1.000000 0.300155 0.292049 0.102465 0.077646 0.134224
Salzburg 0.250008 0.167119 0.082585 0.300155 1.000000 0.149789 0.055089 0.086943 -0.008977
Steiermark 0.069348 -0.117903 0.223043 0.292049 0.149789 1.000000 0.110189 0.108914 -0.101737
Tirol 0.103257 0.147188 0.135035 0.102465 0.055089 0.110189 1.000000 0.166205 0.154929
Vorarlberg -0.049378 0.005515 0.060463 0.077646 0.086943 0.108914 0.166205 1.000000 0.039290
Wien 0.164681 0.320500 0.355938 0.134224 -0.008977 -0.101737 0.154929 0.039290 1.000000